using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace APP.QUANLY.Common
{
    public static class Animation
    {
        public static int animationStep = 1;
        public static Int32 itime = 10;
        public static Point finishLocation;
        public static Panel pnlOldDemo = new Panel();

        public static void ActivateShow_LeftToRight(int StartPosition,Timer boundsTimer, Panel pnlMain,Panel pnlDemo)
        {
            if (pnlDemo == null)
                return;

            pnlMain.Controls.Clear();
            pnlMain.Controls.Add(pnlDemo);
            pnlDemo.Parent = pnlMain;
            pnlDemo.Location = new Point(0,0);
            pnlDemo.Width = pnlMain.Width;
            pnlDemo.Height = pnlMain.Height;
            pnlDemo.BackColor = System.Drawing.Color.Transparent;
            finishLocation = pnlDemo.Location;
            pnlDemo.Location = new Point(-StartPosition, finishLocation.Y);
            pnlDemo.Hide();
            boundsTimer.Start();
        }
        public static void Animation_LeftToRight(Timer boundsTimer,Panel pnlDemo)
        {
            if (finishLocation.X >= 0)
            {
                if (pnlDemo == null)
                {
                    boundsTimer.Stop();
                    return;
                }
                else
                {
                    pnlDemo.Show();
                }

                if (pnlDemo.Location.X < finishLocation.X)
                {
                    pnlDemo.Location = new Point(pnlDemo.Location.X + animationStep, finishLocation.Y);
                    //animationStep++;
                }
                else
                {
                    pnlDemo.Location = finishLocation;
                    pnlOldDemo.Location = finishLocation;
                    boundsTimer.Stop();
                    pnlDemo.Refresh();
                    animationStep = 1;
                    return;
                }
                animationStep++;
            }
            else
            {
                if (pnlOldDemo.Location.X > 0)
                {
                    pnlOldDemo.Location = new Point(pnlOldDemo.Location.X - animationStep, finishLocation.Y);
                }
                else
                {
                    pnlOldDemo.Location = finishLocation;
                    boundsTimer.Stop();
                    pnlOldDemo.Hide();
                    //ActivateShow_LeftToRight(StartPosition, boundsTimer, pnlMain, pnlDemo);
                }
                animationStep++;
            }
            animationStep++;
        }

        public static void Reset(Panel pnlMain, Panel pnlDemo)
        {
            pnlDemo.Width = pnlMain.Width;
            pnlDemo.Height = pnlMain.Height;
        }
    }
}
